<?php

/**
 * @file
 * Provides example of multi forms at one page.
 */

function _register_parent_main_s1(&$form_state, &$next_step, $params) {
    $next_step = '_register_parent_main_s2';

    $controls = mforms_controls_get('parent_main');
    $controls->setControlsLabels(t('Submit'));

    $values = mforms_get_vals('parent_main', '_register_parent_main_s1');
    $form = array();
    $form['chk_YP_9to18'] = array(
      '#weight' => '0',
      '#required' => '1',
      '#key_type_toggled' => '0',
      '#type' => 'radios',
      '#options' => array(
        'Yes' => t('Yes'),
        'No' => t('No'),
      ),
      '#title' => t('Do you have a YP between the ages or 9-18?'),
    );
    
    $form['chk_YP_EntertainmentMember'] = array(
      '#weight' => '1',
      '#required' => '1',
      '#key_type_toggled' => '0',
      '#type' => 'radios',
      '#options' => array(
        'Yes' => t('Yes'),
        'No' => t('No'),
      ),
      '#title' => t('Is your YP a member of an entertainment union? '),
        '#ajax' => array(
          'callback' => '_register_parent_main_load_element',
          'wrapper' => 'new-element-wrapper',
          'method' => 'replace',
          'effect' => 'fade',
        ),
    );
    
    
    $form['new-element-wrapper'] = array(
        '#markup' => '',
        '#suffix' => '</div>',
        '#prefix' => '<br /><div id="new-element-wrapper">',
      );

    if ((isset($values['chk_YP_EntertainmentMember']) && $values['chk_YP_EntertainmentMember']=="No") 
            ||
            ((isset($form_state['values']['chk_YP_EntertainmentMember']) && $form_state['values']['chk_YP_EntertainmentMember']=="No"))
    ){
        $form['new-element-wrapper']['chk_YP_IncomeLast2Yr'] = array(
          '#required' => '1',
          '#key_type_toggled' => '0',
          '#weight' => '-22',
          '#type' => 'radios',
          '#options' => array(
            'Yes' => t('Yes'),
            'No' => t('No'),
          ),
          '#title' => t('Did your YP make $3000/yr for the last 2 years? '),
        );
    }
    
    $form['chk_YP_RepresentedByAgent'] = array(
      '#weight' => '3',
      '#required' => '1',
      '#key_type_toggled' => '0',
      '#type' => 'radios',
      '#options' => array(
        'Yes' => t('Yes'),
        'No' => t('No'),
      ),
      '#title' => t('Is your YP currently represented by an Agent or Manager?'),
    );

    return $form;
}

function _register_parent_main_load_element($form, &$form_state) {
  return $form['new-element-wrapper'];
}

/* Second form step. */
function _register_parent_main_s2(&$form_state, &$next_step, $params) {
  $next_step = '_register_parent_main_s3';

  $values = mforms_get_vals('parent_main', '_register_parent_main_s1');
  
  $controls = mforms_controls_get('parent_main');
  $controls->setControlsLabels(t('Next'));
  $controls->setCancelPath('register/parent/main');

  $form = array();
    $form['txt_FirstName'] = array(
      '#weight' => '0',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('First Name '),
    );
    $form['txt_MiddleName'] = array(
      '#weight' => '1',
      '#required' => '0',
      '#type' => 'textfield',
      '#title' => t('Middle Name '),
    );
    $form['txt_LastName'] = array(
      '#weight' => '2',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Last Name'),
    );
    $form['txt_Username'] = array(
      '#weight' => '3',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('User Name'),
    );
    $form['txt_Email'] = array(
      '#weight' => '4',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Email'),
    );
    $form['txt_Password'] = array(
      '#weight' => '5',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Password'),
    );
    $form['txt_ConfirmPassword'] = array(
      '#weight' => '6',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Confirm Password'),
    );
    
    $form['txt_Phone1'] = array(
      '#weight' => '8',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Phone# 1'),
    );
    $form['txt_Phone2'] = array(
      '#weight' => '7',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Phone# 2'),
    );
    $form['txt_MaritalStatus'] = array(
      '#weight' => '9',
      '#required' => '1',
      '#multiple' => '0',
      '#key_type_toggled' => '0',
      '#type' => 'select',
      '#options' => array(
        '1' => t('Married'),
        '2' => t('Widowed'),
        '3' => t('Separated'),
        '4' => t('Divorced'),
        '5' => t('Single'),
      ),
      '#multiple_toggle' => '1',
      '#title' => t('Martial Status'),
    );
    $form['chk_CA_Resident'] = array(
      '#weight' => '10',
      '#required' => '1',
      '#key_type_toggled' => '0',
      '#type' => 'radios',
      '#options' => array(
        'Yes' => t('Yes'),
        'No' => t('No'),
      ),
      '#title' => t('CA Resident'),
    );
    
    return $form;
}


/* Third form step. */
function _register_parent_main_s3(&$form_state, &$next_step, $params) {
  $next_step = '_register_parent_main_s4';

  $values = mforms_get_vals('parent_main', '_register_parent_main_s3');
  
  $controls = mforms_controls_get('parent_main');
  $controls->setControlsLabels(t('Next'));
  $controls->setCancelPath('register/parent/main');
  
  $form = array();
    $form['txt_PrimaryMailingAddress'] = array(
      '#required' => '1',
      '#default_value' => 'Primary Mailing Address',
      '#weight' => '0',
      '#type' => 'textarea',
      '#title' => t('Primary Mailing Address'),
    );
    $form['txt_ApartmentNo'] = array(
      '#weight' => '1',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Apartment #'),
    );
    $form['txt_City'] = array(
      '#weight' => '2',
      '#required' => '0',
      '#type' => 'textfield',
      '#title' => t('City'),
    );
    $form['txt_City'] = array(
      '#weight' => '3',
      '#required' => '0',
      '#type' => 'textfield',
      '#title' => t('State'),
    );
    $form['txt_City'] = array(
      '#weight' => '4',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Zip'),
    );
    $form['txt_NoOfAdults'] = array(
      '#weight' => '6',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Number Of Adults At This Address'),
    );
    $form['chk_wantMailings'] = array(
      '#weight' => '7',
      '#required' => '1',
      '#key_type_toggled' => '1',
      '#type' => 'radios',
      '#options' => array(
        'Yes' => t('Yes'),
        'No' => t('No'),
      ),
      '#title' => t('Do You Want Mailings At This Address'),
    );
    return $form;
}

/* Fourth Step */
function _register_parent_main_s4(&$form_state, &$next_step, $params) {
  $next_step = '_register_parent_main_s5';

  $values = mforms_get_vals('parent_main', '_register_parent_main_s4');
  
  $form = array();
    $form['txt_LegalFirstName'] = array(
      '#weight' => '0',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Legal First Name'),
    );
    $form['txt_LegalMiddleName'] = array(
      '#weight' => '1',
      '#required' => '0',
      '#type' => 'textfield',
      '#title' => t('Legal Middle Name'),
    );
    $form['txt_LegalLastName'] = array(
      '#weight' => '2',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('Legal Last Name'),
    );
    $form['txt_AKAFirstName'] = array(
      '#weight' => '3',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('AKA First Name'),
    );
    $form['txt_AKALastName'] = array(
      '#weight' => '4',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('AKA Last Name'),
    );
    $form['txt_DOB'] = array(
      '#required' => '1',
      '#description' => t('Date'),
      '#weight' => '5',
      '#type' => 'textfield',
      '#title' => t('DOB'),
    );
    $form['txt_Gender'] = array(
      '#weight' => '6',
      '#required' => '1',
      '#multiple' => '0',
      '#key_type_toggled' => '1',
      '#type' => 'select',
      '#options' => array(
        'Male' => t('Male'),
        'Female' => t('Female'),
      ),
      '#multiple_toggle' => '1',
      '#title' => t('Gender'),
    );
    $form['txt_Ethnicity'] = array(
      '#weight' => '7',
      '#required' => '0',
      '#key_type_toggled' => '1',
      '#type' => 'radios',
      '#options' => array(
        'White' => t('White'),
        'Black or African-American ' => t('Black or African-American'),
        'Hispanic' => t('Hispanic'),
        'Asian' => t('Asian'),
        'American Indian or Alaska Native' => t('American Indian or Alaska Native'),
        'Native Hawaiian or other Pacific Islander' => t('Native Hawaiian or other Pacific Islander'),
      ),
      '#title' => t('Ethnicity'),
    );
    $form['txt_YPCellPhone'] = array(
      '#weight' => '8',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('YP Cell Phone'),
    );
    $form['txt_YPEmail'] = array(
      '#weight' => '9',
      '#required' => '1',
      '#type' => 'textfield',
      '#title' => t('YP Email'),
    );
    $form['chk_AlternateContactMethod'] = array(
      '#weight' => '10',
      '#required' => '1',
      '#key_type_toggled' => '1',
      '#type' => 'radios',
      '#options' => array(
        'Texting' => t('Texting'),
        'Post Mail' => t('Post Mail'),
      ),
      '#title' => t('Alternate Methods Of Contact (Other Then Email)'),
    );
    return $form;
}

function _register_parent_main_s4_submit($form, &$form_state) {
  $_SESSION['field1'] = $form_state['values']['field1'];
  drupal_set_message(t('Information has been updated'));

  $steps = MformsSteps::getInstance(mforms_store_get('parent_main'));
  $steps->overrideNext('_register_parent_main_s1');
}

function _register_parent_main_s5(&$form_state, &$next_step, $params) {
  return _register_parent_main_s1($form_state, $next_step, $params);
}
